###Replication Information for "krige: R Software for Bayesian Universal Kriging"
 by Le Bao, Jason Byers, Jamie Carson, and Jeff Gill###
###DATE: 12/17/2020

################################# OVERVIEW #####################################
[root dir] (root directory) contains all the R scripts. The number in the files 
corresponds to the sequence of the analaysis. Files with names that start with 
A are for Appendix. /data folder contains all the original data or the external 
results we are comparing to. /results folder contains all the results estimated 
or predicted in our analyses. /output folder (with subfolder /fig and /tab) contains 
all the output figures and tables that are used in the LaTex manuscript.

################################# ROOT DIR #####################################
## [root dir]

* 1a.WVwells.R: R script to estimate the natural gas data in West Virginia. The script 
is to reproduce the results in Modeling natural gas production in wells in West 
Virginia. OUTPUT: /results/wv.out.Rdata.

* 1b.WVwells-output.R: Rscript to create all the tables and figures in Appendix A.2.1. 
INPUT: /results/wv.out.Rdata. OUTPUT: /output/tab/wvwells-results.txt (Table 3), 
/output/tab/wvwells-diag.txt (Table 4), /output/tab/wvwells-pred.txt (Table 5), 
/output/fig/semivariogram_wvwells.pdf (Figure 2).

* 2a.fullData-estimation.R: This is the R script to estimate the spatial regression 
model of ideology as a function of demographics and location for the 21,764 respondents 
in the 2008 CCES. INPUT: /data/cces08reformattedFine48.dta. 
OUTPUT: /results/krige.fit1.RData.

* 2b.fullData-update.R: This is the R script to update the model based on 
the results from 1.estimation-fullData.R. INPUT: results/krige.fit1.RData. 
OUTPUT: /results/krige.fit2.RData.

* 2c.fullData-prediction.R: R script that uses model results to predict ideology for 280,428 
simulated citizens, saving predicted ideology alongside random draws of U.S. Census 
data and locational information for the simulated citizens. INPUT: /results/krige.fit2.RData, 
/data/cces08reformattedFine48.dta, /data/krigedPointsFine.csv. 
OUTPUT: /results/predictions.csv.

* 2d.fullData-output.R: This is R script produces all the output for the main text. 
INPUT: /results/krige.fit1.RData, /results/krige.fit2.RData, /results/predictions.csv, 
/data/sppq-results.Rdata. OUTPUT: /output/tab/fullData-diag.txt (Table 3), 
/output/tab/fullData-results.txt (Table 4), /output/fig/semivariogram_fullData.pdf 
(Figure 2), /output/fig/lowerChambersOLD.pdf (Figure 3(a)), /output/fig/lowerChambersNEW.pdf 
(Figure 3(b)).

* A1.congCombined.R: This is R script produces all the output for Appendix 1. It is 
the example code for data congCombined in the package. OUTPUT: output/fig/congDist.pdf 
(Figure A.1.4).

* A2a.nyc.R: R script to estimate the ideology in New York City. The script is to 
reproduce the results in Appendix A.2.2. OUTPUT: /results/nyc.out.Rdata.

* A2b.nyc_output.R: Rscript to create all the tables and figures in Appendix A.2.2. 
INPUT: /results/nyc.out.Rdata. OUTPUT: /output/tab/nyc-results.txt (Table A.2.8), 
/output/tab/nyc-diag.txt (Table A.2.9), /output/tab/nyc-pred.txt (Table A.2.10), 
/output/fig/semivariogram_nyc.pdf (Figure A.2.5).

################################## DATA ########################################
## /data
* cces08reformattedFine48.dta: Cleaned version of the 2008 Cooperative Congressional 
Election Study (CCES) that excludes Alaska and Hawaii. These serve as the training 
data in this analysis.

* krigedPointsFine.csv: Sample of 280,428 simulated citizens, drawn from the 2010 
Census data. 250,000 citizens are locationally drawn in proportion to the population 
of their census block. The remaining simulated citizens were drawn, one apiece, from 
geographic units of interest. This guarantees that there is at least one simulated 
citizen in all 23,764 populated census tracts, in all 4,722 state legislative lower 
chamber districts, and in all 1,942 state legislative upper chamber districts.

* sppq-results.Rdata: Previous results using BRSS for ideology model from Gill (2020) 
<doi:10.1177/1532440020930197>. This is used to compare with the full-information 
model estimated in the present study.

################################# RESULTS ######################################
## /results
* wv.out.Rdata: This R data file contains the output objects produced by WVwells.R
for estimating WV natural gas model.

* krige.fit1.RData: This R data file contains the output objects produced by 
estimation-fullData.R for the 2008 CCES model.

* krige.fit2.RData: This R data file contains the output from update run by 
estimation-update_fullData.R for the 2008 CCES model.

* predictions.csv: This file includes predicted values of ideology for 280,428 
simulated citizens, alongside these kriged points' predictor values that were 
taken from krigedPointsFine.csv.

* nyc.out.Rdata: This R data file contains the output objects produced by WVwells.R
for estimating 2008 NYC ideology model.

################################## OUTPUT ######################################
## /output
## /output/fig: The folder contains all the figure outputs for the main text as 
well as the appendices.
## /output/fig/tab: The folder contains all the table outputs for the main text 
as well as the appendices.